package com.jay.media.music.ui

import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import android.os.StrictMode
import android.util.Log
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.Utils
import com.jay.media.kit.ColorUtils
import com.jay.media.kit.LogHelper
import com.jay.media.music.ui.manager.MusicClientManager

/**
 * Create by xuzhou4
 * Date 2021/11/8
 */
class MediaApplication : Application() {
    private val TAG = LogHelper.makeLogTag(this::class.java)

    companion object {
        @SuppressLint("StaticFieldLeak")
        lateinit var mContext: Context
        fun getContext(): Context {
            return mContext
        }
    }

    override fun onCreate() {
        super.onCreate()
        mContext = this
        Log.d(TAG, "onCreate")
        StrictMode.setThreadPolicy(
            StrictMode.ThreadPolicy.Builder()
                .detectDiskWrites()
                .detectNetwork()
                .penaltyLog()
                .build()
        )
        StrictMode.setVmPolicy(
            StrictMode.VmPolicy.Builder()
                .detectLeakedSqlLiteObjects()
                .detectLeakedClosableObjects()
                .penaltyLog()
                .build()
        )
        Utils.init(this)
        ColorUtils.init(this)

        if (BuildConfig.DEBUG) {
            ARouter.openDebug()
            ARouter.openLog()
        }
        ARouter.init(this)

        MusicClientManager.getClient().init(this)
    }

    override fun onTerminate() {
        super.onTerminate()
        Log.d(TAG, "onTerminate() called")
        ARouter.getInstance().destroy()
    }
}